package com.support.databinding.slice;

import br.com.ilhasoft.support.validation.util.URLUTIL;
import br.com.ilhasoft.support.validation.validator.DateValidator;
import br.com.ilhasoft.support.validation.validator.LengthValidator;
import br.com.ilhasoft.support.validation.validator.PasswordValidator;
import br.com.ilhasoft.support.validation.validator.TypeValidator;
import com.support.databinding.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.TextField;
import ohos.agp.components.Text;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextTool;
import ohos.agp.window.dialog.BaseDialog;
import ohos.agp.window.dialog.PopupDialog;
import ohos.agp.window.dialog.ToastDialog;
import ohos.agp.window.service.WindowManager;


public class MainAbilitySlice extends AbilitySlice {
    private TextField name;
    private TextField userName;
    private TextField email;
    private TextField url;
    private TextField cpf;
    private TextField creditCard;
    private TextField year;
    private TextField month;
    private TextField notEmpty;
    private TextField password;
    private TextField confimPassword;
    private Text name_error;
    private Text username_error;
    private Text email_error;
    private Text url_error;
    private Text cpf_error;
    private Text card_error;
    private Text year_error;
    private Text month_error;
    private Text notEmpty_error;
    private Text password_error;
    private Text confirm_password_error;
    private Button validate;
    private Button to_validate;
    private Button validate_name;
    private Button validate_multiple;
    private Text textName;
    private Text textUsername;
    private Text textEmail;
    private Text textURL;
    private Text textCPF;
    private Text textCard;
    private Text textYear;
    private Text textMonth;
    private Text textNotEmpty;
    private Text textPassword;
    private Text textConfimPassword;
    private Component lineName;
    private Component lineUsername;
    private Component lineEmail;
    private Component lineURL;
    private Component lineCPF;
    private Component lineCard;
    private Component lineYear;
    private Component lineMonth;
    private Component lineNotEmpty;
    private Component linePassword;
    private Component lineConfimPassword;
    private ToastDialog toastDialog;
    private Component dialogView;
    private PopupDialog popupDialog;

    @Override
    public void onStart(Intent intent) {
        //沉浸式状态栏
        getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
    }

    @Override
    public void onActive() {
        super.onActive();
        name = (TextField) findComponentById(ResourceTable.Id_name);
        userName = (TextField) findComponentById(ResourceTable.Id_username);
        email = (TextField) findComponentById(ResourceTable.Id_email);
        url = (TextField) findComponentById(ResourceTable.Id_URL);
        cpf = (TextField) findComponentById(ResourceTable.Id_cpf);
        creditCard = (TextField) findComponentById(ResourceTable.Id_card);
        year = (TextField) findComponentById(ResourceTable.Id_year);
        month = (TextField) findComponentById(ResourceTable.Id_month);
        notEmpty = (TextField) findComponentById(ResourceTable.Id_notEmpty);
        password = (TextField) findComponentById(ResourceTable.Id_password);
        confimPassword = (TextField) findComponentById(ResourceTable.Id_confirm_password);
        name_error = (Text) findComponentById(ResourceTable.Id_name_error);
        username_error = (Text) findComponentById(ResourceTable.Id_username_error);
        email_error = (Text) findComponentById(ResourceTable.Id_email_error);
        url_error = (Text) findComponentById(ResourceTable.Id_url_error);
        cpf_error = (Text) findComponentById(ResourceTable.Id_cpf_error);
        card_error = (Text) findComponentById(ResourceTable.Id_card_error);
        year_error = (Text) findComponentById(ResourceTable.Id_year_error);
        month_error = (Text) findComponentById(ResourceTable.Id_month_error);
        notEmpty_error = (Text) findComponentById(ResourceTable.Id_notEmpty_error);
        password_error = (Text) findComponentById(ResourceTable.Id_password_error);
        confirm_password_error = (Text) findComponentById(ResourceTable.Id_confirm_password_error);
        validate = (Button) findComponentById(ResourceTable.Id_validate);
        to_validate = (Button) findComponentById(ResourceTable.Id_to_validate);
        validate_name = (Button) findComponentById(ResourceTable.Id_validate_name);
        validate_multiple = (Button) findComponentById(ResourceTable.Id_validate_multiple);
        textName = (Text) findComponentById(ResourceTable.Id_textName);
        textUsername = (Text) findComponentById(ResourceTable.Id_textUsername);
        textEmail = (Text) findComponentById(ResourceTable.Id_textEmail);
        textURL = (Text) findComponentById(ResourceTable.Id_textURL);
        textCPF = (Text) findComponentById(ResourceTable.Id_textCPF);
        textCard = (Text) findComponentById(ResourceTable.Id_textCard);
        textYear = (Text) findComponentById(ResourceTable.Id_textYear);
        textMonth = (Text) findComponentById(ResourceTable.Id_textMonth);
        textNotEmpty = (Text) findComponentById(ResourceTable.Id_textNotEmpty);
        textPassword = (Text) findComponentById(ResourceTable.Id_textPassword);
        textConfimPassword = (Text) findComponentById(ResourceTable.Id_textConfirmpassword);
        lineName = findComponentById(ResourceTable.Id_lineName);
        lineUsername = findComponentById(ResourceTable.Id_lineUsername);
        lineEmail = findComponentById(ResourceTable.Id_lineEmail);
        lineURL = findComponentById(ResourceTable.Id_lineURL);
        lineCPF = findComponentById(ResourceTable.Id_lineCPF);
        lineCard = findComponentById(ResourceTable.Id_lineCard);
        lineYear = findComponentById(ResourceTable.Id_lineYear);
        lineMonth = findComponentById(ResourceTable.Id_lineMonth);
        lineNotEmpty = findComponentById(ResourceTable.Id_lineNotEmpty);
        linePassword = findComponentById(ResourceTable.Id_linePassword);
        lineConfimPassword = findComponentById(ResourceTable.Id_lineConfirmpassword);

        validate_name.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                boolean status = LengthValidator.bindingMinLength(name_error, name.getText().toString(), 4,
                        "Custom message: This message is too small!", false);
                if (status) {
                    LengthValidator.bindingMaxLength(name_error, name.getText().toString(), 10,
                            "Custom message: This message is too big!", false);
                }
                if (name_error.getVisibility() == Component.VISIBLE) {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineName.setBackground(element);
                    name.setHint("");
                }
            }
        });

        validate_multiple.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                TypeValidator.bindingTypeValidation(username_error, "username", userName.getText().toString(),
                        "Custom message: Username not valid", false);
                TypeValidator.bindingTypeValidation(email_error, "email", email.getText().toString(),
                        "Invalid email format", false);
                if (username_error.getVisibility() == Component.VISIBLE) {
                    textUsername.setVisibility(Component.VISIBLE);
                    textUsername.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineUsername.setBackground(element);
                    userName.setHint("");
                }
                if (email_error.getVisibility() == Component.VISIBLE) {
                    textEmail.setVisibility(Component.VISIBLE);
                    textEmail.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineEmail.setBackground(element);
                    email.setHint("");
                }
            }
        });

        validate.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                boolean pass = true;
                boolean status = LengthValidator.bindingMinLength(name_error, name.getText().toString(),
                        4, "Custom message: This message is too small!", false);
                if (status) {
                    LengthValidator.bindingMaxLength(name_error, name.getText().toString(), 10,
                            "Custom message: This message is too big!", false);
                }

                if (name_error.getVisibility() == Component.VISIBLE) {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineName.setBackground(element);
                    name.setHint("");
                    pass = false;
                }
                TypeValidator.bindingTypeValidation(username_error, "username", userName.getText().toString(),
                        "Custom message: Username not valid", false);
                TypeValidator.bindingTypeValidation(email_error, "email", email.getText().toString(),
                        "Invalid email format", false);
                if (username_error.getVisibility() == Component.VISIBLE) {
                    textUsername.setVisibility(Component.VISIBLE);
                    textUsername.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineUsername.setBackground(element);
                    userName.setHint("");
                    pass = false;
                }
                if (email_error.getVisibility() == Component.VISIBLE) {
                    textEmail.setVisibility(Component.VISIBLE);
                    textEmail.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineEmail.setBackground(element);
                    email.setHint("");
                    pass = false;
                }

                TypeValidator.bindingTypeValidation(url_error, "url", url.getText().toString(),
                        "Invalid url format", false);
                if (url_error.getVisibility() == Component.VISIBLE) {
                    textURL.setVisibility(Component.VISIBLE);
                    textURL.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineURL.setBackground(element);
                    url.setHint("");
                    pass = false;
                }

                TypeValidator.bindingTypeValidation(cpf_error, "cpf", cpf.getText().toString(),
                        "Custom message: CPF is wrong man!", false);
                if (cpf_error.getVisibility() == Component.VISIBLE) {
                    textCPF.setVisibility(Component.VISIBLE);
                    textCPF.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineCPF.setBackground(element);
                    cpf.setHint("");
                    pass = false;
                }
                TypeValidator.bindingTypeValidation(card_error, "creditcard", creditCard.getText().toString(),
                        "Invalid credit card format", false);
                if (card_error.getVisibility() == Component.VISIBLE) {
                    textCard.setVisibility(Component.VISIBLE);
                    textCard.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineCard.setBackground(element);
                    creditCard.setHint("");
                    pass = false;
                }
                DateValidator.bindingDate(year_error, year.getText().toString(), "yyyy",
                        "Custom message: It's not a date!", false);
                if (year_error.getVisibility() == Component.VISIBLE) {
                    textYear.setVisibility(Component.VISIBLE);
                    textYear.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineYear.setBackground(element);
                    year.setHint("");
                    pass = false;
                }
                DateValidator.bindingDate(month_error, month.getText().toString(), "MM",
                        "Invalid data format", false);
                if (month_error.getVisibility() == Component.VISIBLE) {
                    textMonth.setVisibility(Component.VISIBLE);
                    textMonth.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineMonth.setBackground(element);
                    month.setHint("");
                    pass = false;
                }
                LengthValidator.bindingEmpty(notEmpty_error, notEmpty.getText().toString(), true,
                        null, false);
                if (notEmpty_error.getVisibility() == Component.VISIBLE) {
                    textNotEmpty.setVisibility(Component.HIDE);
                    textNotEmpty.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineNotEmpty.setBackground(element);
                    notEmpty.setHint("Not Empty");
                    pass = false;
                }
                PasswordValidator.bindingPassword(password_error, confirm_password_error, password.getText().toString(),
                        confimPassword.getText().toString(), "Custom message: passwords are not equals!!",
                        false);
                if (password_error.getVisibility() == Component.VISIBLE) {
                    textPassword.setVisibility(Component.VISIBLE);
                    textPassword.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    linePassword.setBackground(element);
                    password.setHint("");
                    textConfimPassword.setVisibility(Component.VISIBLE);
                    textConfimPassword.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    lineConfimPassword.setBackground(element);
                    confimPassword.setHint("");
                    pass = false;
                }
                if (!pass) {
                    toastDialog = new ToastDialog(MainAbilitySlice.this);
                    toastDialog.setOffset(0, 300);
                    toastDialog.setText("Dados inválidos!").setAlignment(LayoutAlignment.BOTTOM).show();
                }
            }
        });

        to_validate.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                boolean pass = true;
                boolean status = LengthValidator.bindingMinLength(name_error, name.getText().toString(), 4,
                        "Custom message: This message is too small!", false);
                if (status) {
                    LengthValidator.bindingMaxLength(name_error, name.getText().toString(), 10,
                            "Custom message: This message is too big!", false);
                }

                if (name_error.getVisibility() == Component.VISIBLE) {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineName.setBackground(element);
                    name.setHint("");
                    pass = false;
                }
                TypeValidator.bindingTypeValidation(username_error, "username", userName.getText().toString(),
                        "Custom message: Username not valid", false);
                TypeValidator.bindingTypeValidation(email_error, "email", email.getText().toString(),
                        "Invalid email format", false);
                if (username_error.getVisibility() == Component.VISIBLE) {
                    textUsername.setVisibility(Component.VISIBLE);
                    textUsername.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineUsername.setBackground(element);
                    userName.setHint("");
                    pass = false;
                }
                if (email_error.getVisibility() == Component.VISIBLE) {
                    textEmail.setVisibility(Component.VISIBLE);
                    textEmail.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineEmail.setBackground(element);
                    email.setHint("");
                    pass = false;
                }

                TypeValidator.bindingTypeValidation(url_error, "url", url.getText().toString(),
                        "Invalid url format", false);
                if (url_error.getVisibility() == Component.VISIBLE) {
                    textURL.setVisibility(Component.VISIBLE);
                    textURL.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineURL.setBackground(element);
                    url.setHint("");
                    pass = false;
                }

                TypeValidator.bindingTypeValidation(cpf_error, "cpf", cpf.getText().toString(),
                        "Custom message: CPF is wrong man!", false);
                if (cpf_error.getVisibility() == Component.VISIBLE) {
                    textCPF.setVisibility(Component.VISIBLE);
                    textCPF.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineCPF.setBackground(element);
                    cpf.setHint("");
                    pass = false;
                }
                TypeValidator.bindingTypeValidation(card_error, "creditcard", creditCard.getText().toString(),
                        "Invalid credit card format", false);
                if (card_error.getVisibility() == Component.VISIBLE) {
                    textCard.setVisibility(Component.VISIBLE);
                    textCard.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineCard.setBackground(element);
                    creditCard.setHint("");
                    pass = false;
                }
                DateValidator.bindingDate(year_error, year.getText().toString(), "yyyy",
                        "Custom message: It's not a date!", false);
                if (year_error.getVisibility() == Component.VISIBLE) {
                    textYear.setVisibility(Component.VISIBLE);
                    textYear.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineYear.setBackground(element);
                    year.setHint("");
                    pass = false;
                }
                DateValidator.bindingDate(month_error, month.getText().toString(), "MM",
                        "Invalid data format", false);
                if (month_error.getVisibility() == Component.VISIBLE) {
                    textMonth.setVisibility(Component.VISIBLE);
                    textMonth.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineMonth.setBackground(element);
                    month.setHint("");
                    pass = false;
                }
                LengthValidator.bindingEmpty(notEmpty_error, notEmpty.getText().toString(), true, null, false);
                if (notEmpty_error.getVisibility() == Component.VISIBLE) {
                    textNotEmpty.setVisibility(Component.HIDE);
                    textNotEmpty.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineNotEmpty.setBackground(element);
                    notEmpty.setHint("Not Empty");
                    pass = false;
                }
                PasswordValidator.bindingPassword(password_error, confirm_password_error, password.getText().toString(),
                        confimPassword.getText().toString(), "Custom message: passwords are not equals!!",
                        false);
                if (password_error.getVisibility() == Component.VISIBLE) {
                    textPassword.setVisibility(Component.VISIBLE);
                    textPassword.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    linePassword.setBackground(element);
                    password.setHint("");

                    textConfimPassword.setVisibility(Component.VISIBLE);
                    textConfimPassword.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    lineConfimPassword.setBackground(element);
                    confimPassword.setHint("");
                    pass = false;
                }
                if (!pass) {
                    toastDialog = new ToastDialog(MainAbilitySlice.this);
                    toastDialog.setOffset(0, 300);
                    toastDialog.setText("Dados inválidos!").setAlignment(LayoutAlignment.BOTTOM).show();
                }
            }
        });

        notEmpty_error.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                setShowDialog();
            }
        });

        year.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int start, int i1, int i2) {
                if (!TextTool.isNullOrEmpty(s) && start < s.length()) {
                    if (s.length() >= 4) {
                        year.setText(s.substring(0, 4));
                    }
                    if (!URLUTIL.isNumeric(s.charAt(start) + "")) {
                        if (s.charAt(start) == '（' || s.charAt(start) == '“') {
                            year.setText(s.substring(0, s.length() - 2));
                        } else {
                            year.setText(s.substring(0, s.length() - 1));
                        }
                    }
                }
            }
        });

        month.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int start, int i1, int i2) {
                if (!TextTool.isNullOrEmpty(s) && start < s.length()) {
                    if (s.length() >= 2) {
                        month.setText(s.substring(0, 2));
                    }
                    if (!URLUTIL.isNumeric(s.charAt(start) + "")) {
                        if (s.charAt(start) == '（' || s.charAt(start) == '“') {
                            month.setText(s.substring(0, s.length() - 2));
                        } else {
                            month.setText(s.substring(0, s.length() - 1));
                        }
                    }
                }
            }
        });

        name.addTextObserver(new Text.TextObserver() {
            @Override
            public void onTextUpdated(String s, int i, int i1, int i2) {
                boolean status = LengthValidator.bindingMinLength(name_error, s, 4,
                        "Custom message: This message is too small!", false);
                if (status) {
                    LengthValidator.bindingMaxLength(name_error, s, 10,
                            "Custom message: This message is too big!", false);
                }
                if (name_error.getVisibility() == Component.VISIBLE) {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF5860")));
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF5860")));
                    lineName.setBackground(element);
                } else {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF4081")));
                    name.setHint("");
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                    lineName.setBackground(element);
                }
            }
        });

        name.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (b) {
                    textName.setVisibility(Component.VISIBLE);
                    textName.setTextColor(new Color(Color.getIntColor("#FF4081")));
                    name.setHint("");
                    ShapeElement element = new ShapeElement();
                    element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                    lineName.setBackground(element);
                } else {
                    if (name_error.getVisibility() != Component.VISIBLE) {
                        if (!TextTool.isNullOrEmpty(name.getText().toString())) {
                            textName.setVisibility(Component.VISIBLE);
                            textName.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textName.setVisibility(Component.HIDE);
                            name.setHint("Name");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineName.setBackground(element);
                    }
                }
            }
        });

        userName.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (username_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textUsername.setVisibility(Component.VISIBLE);
                        textUsername.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        userName.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineUsername.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(userName.getText().toString())) {
                            textUsername.setVisibility(Component.VISIBLE);
                            textUsername.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textUsername.setVisibility(Component.HIDE);
                            userName.setHint("Username");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineUsername.setBackground(element);
                    }
                }
            }
        });

        email.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (email_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textEmail.setVisibility(Component.VISIBLE);
                        textEmail.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        email.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineEmail.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(email.getText().toString())) {
                            textEmail.setVisibility(Component.VISIBLE);
                            textEmail.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textEmail.setVisibility(Component.HIDE);
                            email.setHint("Email");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineEmail.setBackground(element);
                    }
                }
            }
        });

        url.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (url_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textURL.setVisibility(Component.VISIBLE);
                        textURL.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        url.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineURL.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(url.getText().toString())) {
                            textURL.setVisibility(Component.VISIBLE);
                            textURL.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textURL.setVisibility(Component.HIDE);
                            url.setHint("URL");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineURL.setBackground(element);
                    }
                }
            }
        });

        cpf.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (cpf_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textCPF.setVisibility(Component.VISIBLE);
                        textCPF.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        cpf.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineCPF.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(cpf.getText().toString())) {
                            textCPF.setVisibility(Component.VISIBLE);
                            textCPF.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textCPF.setVisibility(Component.HIDE);
                            cpf.setHint("CPF");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineCPF.setBackground(element);
                    }
                }
            }
        });
        creditCard.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (card_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textCard.setVisibility(Component.VISIBLE);
                        textCard.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        creditCard.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineCard.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(creditCard.getText().toString())) {
                            textCard.setVisibility(Component.VISIBLE);
                            textCard.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textCard.setVisibility(Component.HIDE);
                            creditCard.setHint("Credit Card");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineCard.setBackground(element);
                    }
                }
            }
        });

        year.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (year_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textYear.setVisibility(Component.VISIBLE);
                        textYear.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        year.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineYear.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(year.getText().toString())) {
                            textYear.setVisibility(Component.VISIBLE);
                            textYear.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textYear.setVisibility(Component.HIDE);
                            year.setHint("Year");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineYear.setBackground(element);
                    }
                }
            }
        });

        month.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (month_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textMonth.setVisibility(Component.VISIBLE);
                        textMonth.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        month.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineMonth.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(month.getText().toString())) {
                            textMonth.setVisibility(Component.VISIBLE);
                            textMonth.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textMonth.setVisibility(Component.HIDE);
                            month.setHint("Month");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineMonth.setBackground(element);
                    }
                }
            }
        });

        notEmpty.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (notEmpty_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textNotEmpty.setVisibility(Component.HIDE);
                        textNotEmpty.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        notEmpty.setHint("Not Empty");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineNotEmpty.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(notEmpty.getText().toString())) {
                            textNotEmpty.setVisibility(Component.HIDE);
                            textNotEmpty.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textNotEmpty.setVisibility(Component.HIDE);
                            notEmpty.setHint("Not Empty");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineNotEmpty.setBackground(element);
                    }
                }
            }
        });

        password.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (password_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textPassword.setVisibility(Component.VISIBLE);
                        textPassword.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        password.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        linePassword.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(password.getText().toString())) {
                            textPassword.setVisibility(Component.VISIBLE);
                            textPassword.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textPassword.setVisibility(Component.HIDE);
                            password.setHint("Password");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        linePassword.setBackground(element);
                    }
                }
            }
        });
        confimPassword.setFocusChangedListener(new Component.FocusChangedListener() {
            @Override
            public void onFocusChange(Component component, boolean b) {
                if (confirm_password_error.getVisibility() != Component.VISIBLE) {
                    if (b) {
                        textConfimPassword.setVisibility(Component.VISIBLE);
                        textConfimPassword.setTextColor(new Color(Color.getIntColor("#FF4081")));
                        confimPassword.setHint("");
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#FF4081")));
                        lineConfimPassword.setBackground(element);
                    } else {
                        if (!TextTool.isNullOrEmpty(confimPassword.getText().toString())) {
                            textConfimPassword.setVisibility(Component.VISIBLE);
                            textConfimPassword.setTextColor(new Color(Color.getIntColor("#999999")));
                        } else {
                            textConfimPassword.setVisibility(Component.HIDE);
                            confimPassword.setHint("Confirm password");
                        }
                        ShapeElement element = new ShapeElement();
                        element.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#000000")));
                        lineConfimPassword.setBackground(element);
                    }
                }
            }
        });
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    /**
     * 初始化设置显示dialog
     */
    private void setShowDialog() {
        dialogView = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_dialog_select, null, false);
        popupDialog = new PopupDialog(getContext(), month_error);
        popupDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP);
        popupDialog.setCustomComponent(dialogView);
        popupDialog.setDialogListener(new BaseDialog.DialogListener() {
            @Override
            public boolean isTouchOutside() {
                setRemoveDialog();
                return false;
            }
        });
        popupDialog.show();
    }

    /**
     * 销毁dialog
     */
    private void setRemoveDialog() {
        dialogView = null;
        popupDialog.remove();
        popupDialog.destroy();
    }
}
